package 动态代理;

import java.lang.reflect.Proxy;

/**
 * 面向切面编程的原理
 */
public class Main {
    public static void main(String[] args) {
        UserServiceImpl userService = new UserServiceImpl();
        MyInvocationHandler myInvocationHandler = new MyInvocationHandler(userService);
        UserService userServiceProxy = (UserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(), userService.getClass().getInterfaces(), myInvocationHandler);

        System.out.println(userServiceProxy.getName(1));
        System.out.println();
        System.out.println();
        System.out.println(userServiceProxy.getAge(2));
    }
}
